/*
 * AddTableModel.java
 *
 * This class defines the table model for tables
 * used  in the AddHouseholdGUI.
 *
 * Created on Apr 30, 2011, 8:59:18 PM
 */

package gui;
import javax.swing.table.*;

/**
 *
 * @author Sarah Wegner
 */

    class AddTableModel extends DefaultTableModel {
        private String[] colNames;
        private Object[][] rowData;
        AddTableModel(Object[][] rowData, String[] colNames){
            super(rowData, colNames);
            this.colNames = colNames;
            this.rowData = rowData;
        }

        @Override
        public Class getColumnClass(int columnIndex) {
            return getValueAt(0, columnIndex).getClass();
        }

        @Override
        public String getColumnName(int col) {
            return colNames[col];
        }

        public boolean isCellSelected(int rowIndex, int columnIndex){
            return true;
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            int colCount = getColumnCount();
            String colName = getColumnName(0);

            //Detect the "Existing Dependent Tab"
            //Existing Dependent information should be un-editable.
            if(colName.equalsIgnoreCase("Dependent")){//colCount==7 means it is the family tab
                //make all columns except for the "Dependent" column to be un-editable.
                if((columnIndex < colCount) && (columnIndex >=1)){
                    return false;
                }//if
            }//if
            return true;
        }//isCellEditable

    }//AddTableModel